package operation;

import book.BookList;

import java.util.Scanner;

public class BackOperation implements Ioperation{//还书操作
    public void work(BookList bookList){
        while(true) {//循环——》可还多本书
            boolean isBorrow=false;//只是为了判断是否有你下面输入的那本书。
            Scanner ip = new Scanner(System.in);
            System.out.println("输入要查找的书名：");
            String name = ip.nextLine();
            for (int i = 0; i < bookList.getNum(); i++) {
                if (name.equals(bookList.getBook(i).getName())&&bookList.getBook(i).isBorrow()==true) {
                    System.out.println("还书成功");
                    bookList.getBook(i).setBorrow(false);
                    isBorrow=true;
                    break;
                }
                else if (name.equals(bookList.getBook(i).getName())&&bookList.getBook(i).isBorrow()==false){
                    System.out.println("这本书未被借出...");
                    isBorrow=true;
                    break;
                }

                if (i== bookList.getNum()-1&&!isBorrow)
                    System.out.println("没有找到这本书");
            }
            System.out.println("是否继续还书");
            System.out.println("1.还书  2.退出");
            int out = ip.nextInt();
            if (out == 2)
                break;
        }
    }
}
